﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using NUnit.Framework;

namespace pwestcott.Util.Tests.Essence.Equals
{
    [TestFixture]
    public class EqualsOrder
    {
        class OrderChecker : IEquatable<OrderChecker>
        {
            public static int CurrentOrder;
            public readonly int Order;

            public OrderChecker(int expectedOrder)
            {
                Order = expectedOrder;
            }

            public bool Equals(OrderChecker other)
            {
                return Order == CurrentOrder++;
            }
        }

        class TestEssence
        {
            [Essence(Order = 1, UseIn=EssenceFunctions.Equals)] OrderChecker first = new OrderChecker(1);
            [Essence(Order = 2, UseIn=EssenceFunctions.Equals)] OrderChecker second = new OrderChecker(2);
            [Essence(Order = 3, UseIn=EssenceFunctions.Equals)] OrderChecker third = new OrderChecker(3);
        }

        [Test]
        public void Test()
        {
            OrderChecker.CurrentOrder = 1;
            Assert.IsTrue(Essence<TestEssence>.EqualsStatic(new TestEssence(), new TestEssence()));
            Assert.AreEqual(4, OrderChecker.CurrentOrder);
        }
    }
}
